﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace TestUtilities
{
	public static class AssertExtensions
	{
		public static void ArraysEqual<T>(IEnumerable<T> argExpected, IEnumerable<T> argActual)
		{
			Assert.AreEqual(argExpected.Count(), argActual.Count());
			Assert.IsTrue(argExpected.Any(item => argActual.Contains(item)));
		}

		public static T Throws<T>(Action argAction) where T : Exception
		{
			T tmpResult = null;

			if (argAction == null)
			{
				throw new ArgumentNullException("argAction");
			}

			try
			{
				argAction();
				Assert.Fail("Exception of type {0} was expected", typeof(T).Name);
			}
			catch (T ex)
			{
				tmpResult = ex;
			}

			return tmpResult;
		}
	}
}
